﻿using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;
using Verse.AI;

namespace Meow
{

    //[HarmonyPatch(typeof(FloatMenuMakerMap), "AddHumanlikeOrders", new Type[] { typeof(Vector3), typeof(Pawn), typeof(List<FloatMenuOption>) })]
    //static class Patch_AddDraftedOrders
    //{

    //    static void Postfix(Vector3 clickPos, Pawn pawn, List<FloatMenuOption> opts)
    //    {
    //        foreach (LocalTargetInfo current in GenUI.TargetsAt(clickPos, TargetingParameters.ForPawns(), true))
    //        {
    //            if (current.Thing is Pawn target)
    //            {
    //                var carrier = target.TryGetComp<Comp_ThingCarrier>();
    //                if (carrier == null) continue;

    //                if (Comp_ThingCarrier.CarryingOffset.ContainsKey(pawn))
    //                {
    //                    if (carrier.Carrying == pawn)
    //                    {
    //                        opts.Add(new FloatMenuOption("Dismount", () => {
    //                            //target.jobs.StopAll();
    //                            //target.jobs.EndCurrentJob(JobCondition.InterruptForced, false, false); //The StopAll above will trigger the WaitForRider job. This will stop it.
    //                            //target.pather.StopDead();
    //                            pawn.jobs.StopAll();
    //                            pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false, false);
    //                            pawn.jobs.TryTakeOrderedJob(new Job(PawnMountDefs.Job_Dismount, target) { count = 1 });

    //                        }, MenuOptionPriority.Low));
    //                    }
    //                }
    //                else
    //                {
    //                    opts.Add(new FloatMenuOption("TryMount", () => {
    //                        target.jobs.StopAll();
    //                        target.jobs.EndCurrentJob(JobCondition.InterruptForced, false, false); //The StopAll above will trigger the WaitForRider job. This will stop it.
    //                        target.pather.StopDead();
    //                        pawn.jobs.TryTakeOrderedJob(new Job(PawnMountDefs.Job_GoAndMountOn, target) { count = 1 });
    //                        pawn.jobs.TryTakeOrderedJob(new Job(PawnMountDefs.Job_BeingCarried) { count = 1 });

    //                    }, MenuOptionPriority.Low));
    //                }
    //                return;
    //            }

    //        }
    //    }
    //}
}
